package com.liuceng.zen.service;

import com.liuceng.zen.mapper.GroupNotThroughReasonMapper;
import com.liuceng.zen.pojo.domain.GroupNotThroughReason;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lijunhao on 16-11-4.
 */
@Service
public class GroupNotThroughReasonService extends BaseService<GroupNotThroughReason>{
    private static final Integer NOT_HANDLE = 1;
    private static final Integer HANDLED = 2;

    @Autowired
    private GroupNotThroughReasonMapper groupNotThroughReasonMapper;

    public List<GroupNotThroughReason> getNeedRead(Integer memberId){
        Map<String,Object> map = new HashMap<>();
        map.put("memberId",memberId);
        map.put("state",NOT_HANDLE);
        return groupNotThroughReasonMapper.getReason(map);
    }

    public List<GroupNotThroughReason> getAllReason(Integer memberId){
        Map<String,Object> map = new HashMap<>();
        map.put("memberId",memberId);
        map.put("state",null);
        return groupNotThroughReasonMapper.getReason(map);
    }

    public void updateReason(Integer memberId){
        List<GroupNotThroughReason> reasons = getNeedRead(memberId);
        if(reasons.size()>0&&reasons!=null){
            for(int i=0;i<reasons.size();i++){
                reasons.get(i).setState(HANDLED);
                groupNotThroughReasonMapper.updateByPrimaryKeySelective(reasons.get(i));
            }
        }
    }

    public GroupNotThroughReason getResultOne(Integer frontAdGroupId){
        Map<String,Object> map = new HashMap<>();
        map.put("frontAdGroupId",frontAdGroupId);
        return groupNotThroughReasonMapper.getResultOne(map);
    }
}
